﻿@{
    ViewBag.Title = "出库单据信息";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script type="text/javascript">
    var rowData = {};
    var FDocuNO = $.request("FDocuNO");
    $(function () {
        initControl();
        gridList();
        if (!!FDocuNO) {
            $.ajax({
                url: "/WareHouse/EnterWareHouse/GetStoCPKConAccoItem",
                data: { fdocuno: FDocuNO },
                dataType: "json",
                async: false,
                success: function (data) {
                    $("#item").formSerialize(data,"txt");
                }
            });
        }
    });
    function initControl() {
        //发生方式
        $("#txtFDocuTypeNO").bindSelect({
            url: "/BaseData/BUS_SJ_Dictionary/GetGridJson?keyword=CF",
            id: "UseUnit",
            search: true,
            text: "FTypeName",
        });
        //来料单位
        $("#txtFHappenComNO").bindSelect({
           url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson?isProduct=1",
           id: "UnitNO",
           search: true,
           text: "UnitNOShortName"
       });
        //零件分类
        $("#txtFProductionTypeNO").bindSelect({
            url: "/VBaseData/V_BUS_SJ_Dictionary/GetPartClass",
            id: "FTypeNO",
            text: "FTypeNOName"
        });
        //零件编号 
        $("#txtFProductionNO").bindSelect({
            url: "/VBaseData/V_ZSJ_12_GH_SuProduction_DatStorKW/SelectPartForDropList",
            id: "FProductionNO",
            text: "FProductionNO",
            search: true
        });
        //仓库编号
        $("#txtFStoreNO").bindSelect({
            url: "/BaseData/CPK_ZD_11_DatStoreHouse/GetStoreHouses",
            id: "FStoreNO",
            text: "FStoreNO",
            search: true
        });
        ////定置编号
        $("#txtFStoreSetNO").bindSelect();
        $("#txtFStoreNO").on("change", function () {
            //定置编号
            $("#txtFStoreSetNO").clearSelect();
            //定置编号
            $("#txtFStoreSetNO").bindSelect({
                url: "/BaseData/CPK_ZD_12_DatStoreHouseSet/StoreHouseSets",
                id: "FStoreSetNO",
                text: "FStoreSetNO",
                param: { storeNO: $("#txtFStoreNO").val()},
                search: true
            });
        });
        //供货单位
        $("#txtFProCompanyNO").bindSelect({
            url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson?isProduct=1",
            id: "UnitNO",
            text: "UnitNOShortName"
        });
        //制造厂家选择
        $("#txtSelectFProCompanyNO").bindSelect({
            url: "/BaseData/ZSJ_B1_GH_SI/GetGridJson?isProduct=1",
            id: "UnitNO",
            text: "UnitNOShortName"
        });
        
        //容器编号
        $("#txtFContainerNO").bindSelect({
            url: "/BaseData/ZSJ_21_RQ_DatContainer/GetGridJson",
            id: "FContainerNO",
            text: "FContainerNO"
        });
        //托盘编号
        $("#txtFPalletNO").bindSelect({
            url: "/BaseData/ZSJ_22_TP_Pallet/GetGridJson",
            id: "PalletNO",
            text: "PalletNO"
        });
        //初始化单据日期
        $("#txtFCurDate").val(new Date().format("yyyy-MM-dd"));
        //绑定计算
        Calculate();
    }

    function gridList() {
        var $gridList = $("#gridList");
        $gridList.dataGrid({
            url: "/VBaseData/V_ZSJ_12_GH_SuProduction_DatStorKW/SelectPart",
            height: 340,
            postData: { fdocuNO: $("#txtFDocuNO").val() },
            colModel: [
           { label: '零件编号', name: 'FProductionNO', width: 120, align: 'left' },
           { label: '零件名称', name: 'FProductionName', width: 120, align: 'left' },
           { label: '零件分类编码', name: 'FProductionTypeNO', width: 120, align: 'left', hidden: true },
           { label: '零件分类', name: 'FProductionTypeName', width: 120, align: 'left' },
           { label: '仓库编号', name: 'FStoreNO', width: 120, align: 'left' },
           { label: '库位编码', name: 'FStoreSetNO', width: 120, align: 'left' },
           { label: '容器编号', name: 'FContainerNO', width: 60, align: 'left' },
           { label: '容器名称', name: 'FContainerName', width: 80, align: 'left' },
           { label: '容器数量', name: 'FContainerQuantity', width: 80, align: 'left' },
           { label: '标准装箱', name: 'Fcontent', width: 60, align: 'left' },
           { label: '实际装箱', name: 'FFactContent', width: 60, align: 'left' },
           { label: '制造单位', name: 'FProCompanyNO', width: 100, align: 'left' },
           { label: '制造单位名称', name: 'FProCompanyName', width: 120, align: 'left' },
           { label: '价格', name: 'Fprice', width: 120, align: 'left', hidden: true }
            ],
            pager: "#gridPager",
            sortname:'FProductionNO desc',
            viewrecords: true,
            onSelectRow: function (rowId) {
                rowData = $gridList.jqGrid('getRowData', rowId);
                $("#detail").formSerialize(rowData, "txt");
                $("#txtFPalletContent").val(rowData.Fcontent);
                $("#FPalletContent").val(rowData.Fcontent);
            }
        });
        $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { keyword: $("#F_ItemCode").val() },
            }).trigger('reloadGrid');
        });
    }

    function Save() {
        if (!$('#item').formValid()) {
            return false;
        }
        if (!$('#detail').formValid()) {
            return false;
        }
        var postData = $("#item").formSerialize();

        postData["detail"] = JSON.stringify($("#detail").formSerialize());
      
        $.ajax({
            url: "/WareHouse/EnterWareHouse/SaveReturnRemainItem",
            data: postData,
            type: "post",
            async: false,
            dataType: "json",
            success: function (data) {
                if (data.state == "success") {
                    $("#txtFDocuNO").val(data.data);
                    $.modalMsg(data.message, data.state);
                } else {
                    $.modalAlert(data.message, data.state);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.loading(false);
                $.modalMsg(errorThrown, "error");
            },
            beforeSend: function () {
                $.loading(true, "正在提交数据...");
            },
            complete: function () {
                $.loading(false);
            }
        });

        return $("#item").formSerialize();
    }
   
    function Calculate() {
        $("#detail").find(".decimal").keyup(function () {
            var $FQuantity_KP = $("#txtFQuantity_KP").val();
            $("#txtFQuantity").val($FQuantity_KP);
            var $FPalletContent = $("#txtFPalletContent").val();
            var $FPalletFactContent = 1; 
            if ($FPalletContent != "") {
                $FPalletFactContent=Math.ceil($FQuantity_KP / $FPalletContent);
            }
            $("#txtFPalletFactContent").val($FPalletFactContent);
        });
    }
    
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-center">
       
            <div style="padding-top: 1px;margin-left:10px;margin-right:10px;">

                <form id="item">
                    <table class="form" style="margin:10px 0;">
                        <tr>
                            <th class="formTitle">发生方式</th>
                            <td class="formValue" style="width:160px;">
                                <select id="txtFDocuTypeNO" name="FDocuTypeNO" class="form-control required">
                                    <option>==请选择==</option>
                                </select>
                            </td>
                            <th class="formTitle" style="width:100px;">摘要说明</th>
                            <td class="formValue">
                                <input id="txtFDescription" name="FDescription" type="text" class="form-control" />
                            </td>
                            <th class="formTitle" style="width:100px;">单据编号</th>
                            <td class="formValue">
                                <input id="txtFDocuNO" name="FDocuNO" type="text" readonly="readonly" class="form-control" />
                            </td>
                        </tr>
                        <tr>
                            <th class="formTitle" style="width:100px;">来料单位</th>
                            <td class="formValue" style="width:120px;">
                                <select id="txtFHappenComNO" name="FHappenComNO" class="form-control ">
                                    <option>==请选择==</option>
                                </select>
                            </td>
                            <th class="formTitle" style="width:100px;">单据日期</th>
                            <td class="formValue" style="width:120px;height:20px;">
                                <input id="txtFCurDate" name="FCurDate" type="text" class="form-control required" onfocus="WdatePicker()" />
                            </td>
                            <th class="formTitle" style="width:100px;">凭证编号</th>
                            <td class="formValue" style="width:120px;height:20px;">
                                <input id="txtFCredence" name="FCredence" type="text" class="form-control " />
                            </td>
                        </tr>
                    </table>
                    </form>

                <hr style="margin-top:10px;margin-bottom:10px;" />

                <form id="detail">
                    <table class="form" style="border:1px solid #ddd;">
                        <tr>
                            <th class="formTitle">零件分类</th>
                            <td class="formValue" style="width:160px;">
                                <select id="txtFProductionTypeNO" name="FProductionTypeNO" class="form-control required">
                                    <option>==请选择==</option>
                                </select>
                            </td>
                            <th class="formTitle" style="width:100px;">零件编号</th>
                            <td class="formValue">
                                <select id="txtFProductionNO" name="FProductionNO" class="form-control required">
                                    <option>==请选择==</option>
                                </select>
                            </td>
                            <th class="formTitle" style="width:100px;">零件名称</th>
                            <td class="formValue">
                                <input id="txtFProductionName" name="FProductionName" type="text" readonly="readonly" class="form-control " />
                            </td>
                        </tr>

                        <tr>
                            <th class="formTitle">仓库编号</th>
                            <td class="formValue" style="width:160px;">
                                <select id="txtFStoreNO" name="FStoreNO" class="form-control required">
                                    <option>==请选择==</option>
                                </select>
                            </td>
                            <th class="formTitle" style="width:100px;">定置编号</th>
                            <td class="formValue">
                                <select id="txtFStoreSetNO" name="FStoreSetNO" class="form-control required">
                                    <option>==请选择==</option>
                                </select>
                            </td>
                            <th class="formTitle" style="width:100px;">批次号</th>
                            <td class="formValue">
                                <input id="txtFBatchNo" name="FBatchNo" type="text" class="form-control " />
                            </td>
                        </tr>

                        <tr>
                            <th class="formTitle">供货单位</th>
                            <td class="formValue" style="width:160px;">
                                <select id="txtFProCompanyNO" name="FSupplierNO" class="form-control required">
                                    <option>==请选择==</option>
                                </select>
                            </td>
                            <th class="formTitle" style="width:100px;">开票数量</th>
                            <td class="formValue">
                                <input id="txtFQuantity_KP" name="FQuantity_KP" type="text" class="form-control text-right required decimal" style="width:80px;margin-left:0px;" />
                                <input id="txtFQuantity" name="FQuantity" type="hidden" />
                            </td>
                            <th class="formTitle" style="width:100px;">零件单价</th>
                            <td class="formValue">
                                <input id="txtFprice" name="FPrice_KP" type="text" class="form-control text-right required decimal" style="width:80px;margin-left:0px;" />
                            </td>
                        </tr>

                        <tr>
                            <th class="formTitle">备注</th>
                            <td class="formValue" style="width:160px;">
                                <input name="FDescription" type="text" class="form-control" />
                            </td>
                        </tr>
                    </table>

                    <table class="form" style="border:1px solid #ddd;margin-top:12px;">
                        <tr>
                            <th class="formTitle">容器编号</th>
                            <td class="formValue" style="width:160px;">
                                <select id="txtFContainerNO" name="FContainerNO" class="form-control required">
                                    <option>==请选择==</option>
                                </select>
                            </td>
                            <th class="formTitle" style="width:100px;"></th>
                            <td class="formValue">
                                <input id="txtIsEmptyBox" type="checkbox" />是否空箱入库
                            </td>
                            <th class="formTitle" style="width:100px;">实际装箱数</th>
                            <td class="formValue">
                                <input id="txtFPalletContent" name="FPalletContent" type="text" class="form-control text-right required decimal" style="width:80px;margin-left:0px;" /><label class="suffix">件/箱</label>
                            </td>
                        </tr>

                        <tr>
                            <th class="formTitle">容器名称</th>
                            <td class="formValue" style="width:160px;">
                                <input id="txtFContainerName" name="FContainerName" type="text" class="form-control  " readonly="readonly" />
                            </td>
                            <th class="formTitle" style="width:100px;">容器数量</th>
                            <td class="formValue">
                                <input id="txtFPalletFactContent" name="FPalletFactContent" type="text" class="form-control text-right required decimal" style="width:80px;margin-left:0px;" />
                            </td>
                            <th class="formTitle" style="width:100px;">标准装箱数</th>
                            <td class="formValue">
                                <input id="txtFcontent" name="Fcontent" type="text" readonly="readonly" class="form-control text-right" style="width:80px;margin-left:0px;" /><label class="suffix">件/箱</label>
                            </td>
                        </tr>

                    </table>
                </form>
            </div>
        <hr style="margin-top:10px;margin-bottom:0px;" />

        <div>
            <table class="form">
                <tr>
                    <th class="formTitle" style="width:60px;">零部件号</th>
                    <td class="formValue" style="width:120px;">
                        <input id="txtFProductionNO1" class="form-control " type="text">
                    </td>
                    <th class="formTitle" style="width:60px;">零件名称</th>
                    <td class="formValue" style="width:120px;">
                        <input id="txtFProductionName1" class="form-control " type="text">
                    </td>
                    <th class="formTitle" style="width:60px;">制造厂家</th>
                    <td class="formValue" style="width:140px;">
                        <select id="txtSelectFProCompanyNO"  onchange="selectChange();" class="form-control">
                            <option>==请选择==</option>
                        </select>
                    </td>
                    <td style="padding: 5px 5px;">
                        <div class="btn-group" style="margin-left:40px;margin-bottom:-2px;">
                            <a id="btn_search" class="btn btn-primary center-block  " onclick="btn_search();"><span class="glyphicon glyphicon-search"></span> 查询</a>
                        </div>
                    </td>
                </tr>
            </table>
        </div>
        <div >
            <table id="gridList"></table>
            <div id="gridPager"></div>
        </div>
    </div>
</div>